package com.taomu.app.zongchouhuli.moudle.home.activity;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.taomu.app.zongchouhuli.R;
import com.taomu.app.zongchouhuli.framework.BaseActivity;
import com.taomu.app.zongchouhuli.framework.BasePresenter;
import com.taomu.app.zongchouhuli.http.res.ResSubmitOrderEntity;
import com.taomu.app.zongchouhuli.moudle.home.contract.HomeOrderContract;
import com.taomu.app.zongchouhuli.moudle.home.contract.impl.HomeOrderPresenter;
import com.taomu.app.zongchouhuli.moudle.mine.activity.UserPatSuccessActivity;
import com.taomu.app.zongchouhuli.moudle.mine.activity.UserRechargeResultsActivity;
import com.taomu.app.zongchouhuli.utils.dialog.PayPasswordDialog;

import static com.taomu.app.zongchouhuli.moudle.home.activity.HomeOrderSubmitActivity.DISTRIBUTION;
import static com.taomu.app.zongchouhuli.moudle.home.activity.HomeOrderSubmitActivity.INCOMETYPE;
import static com.taomu.app.zongchouhuli.moudle.home.activity.HomeOrderSubmitActivity.PRODUCTID;
import static com.taomu.app.zongchouhuli.moudle.home.activity.HomeOrderSubmitActivity.PRODUCTMONEY;
import static com.taomu.app.zongchouhuli.moudle.home.activity.HomeOrderSubmitActivity.PRODUCTNAME;
import static com.taomu.app.zongchouhuli.moudle.home.activity.HomeOrderSubmitActivity.PRODUCTRADIO;
import static com.taomu.app.zongchouhuli.moudle.home.activity.HomeOrderSubmitActivity.QUANTITY;

public class HomePayActivity extends BaseActivity<HomeOrderContract.Presenter> implements HomeOrderContract.View {

    private ImageView mBackim;

    private TextView mPriceTv;

    private TextView mOrderNumTv;

    private TextView mConfirmTv;

    private String distribution = "";

    private String content = "";

    private String productid = "";

    public static final String PAYMONEY = "paymoney";

    public static final String PAYPRODUCTID = "poriudcutid";

    public static final String PAYORDERNUM = "payordernum";

    public static final String PAYORDERID = "payorderid";

    public static final String PAYDISTRIBUTIION = "paydisipdqwd";

    private String orderid = "";

    public static void start(Context mContext, String productid, String ordernum,String orderid,String money,String distribution){
        Intent intent = new Intent(mContext,HomePayActivity.class);
        intent.putExtra(PAYPRODUCTID,productid);
        intent.putExtra(PAYORDERNUM,ordernum);
        intent.putExtra(PAYORDERID, orderid);
        intent.putExtra(PAYMONEY, money);
        intent.putExtra(PAYDISTRIBUTIION, distribution);
        mContext.startActivity(intent);
    }

    @Override
    protected int getContentLayout() {
        return R.layout.activity_home_pay__pay;
    }

    @Override
    protected void initView() {
        mBackim = findViewById(R.id.recharge_confirm_back_im);
        mPriceTv = findViewById(R.id.recharge_confirm_price_tv);
        mOrderNumTv = findViewById(R.id.confirm_order_num);
        mConfirmTv = findViewById(R.id.confirm_submit_tv);
    }

    @Override
    protected void initData() {
        if(!TextUtils.isEmpty(getIntent().getStringExtra(PAYPRODUCTID))) {
            productid = getIntent().getStringExtra(PRODUCTID);
        }
        if(!TextUtils.isEmpty(getIntent().getStringExtra(PAYDISTRIBUTIION))) {
            distribution = getIntent().getStringExtra(PAYDISTRIBUTIION);
        }
        if(!TextUtils.isEmpty(getIntent().getStringExtra(PAYORDERID))){
            orderid = getIntent().getStringExtra(PAYORDERID);
        }
        String ordernum = getIntent().getStringExtra(PAYORDERNUM);

        String money = getIntent().getStringExtra(PAYMONEY);
        content = "¥"+money;
        mPriceTv.setText(content);
        mOrderNumTv.setText("订单编号:"+ordernum);
    }

    @Override
    protected void initEvent() {
        mConfirmTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PayPasswordDialog dialog = new PayPasswordDialog(HomePayActivity.this);
                dialog.setContent(content);
                dialog.setPayPasswordListener(new PayPasswordDialog.PayPasswordListener() {
                    @Override
                    public void onFinishInput(String pwd) {
                        mPresenter.setsubmit(orderid, pwd, productid,distribution);
                    }
                });
                dialog.show();
            }
        });
        mBackim.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected HomeOrderContract.Presenter createPresenter() {
        return new HomeOrderPresenter(this);
    }

    @Override
    public void setOrderInfo(ResSubmitOrderEntity entity) {

    }

    @Override
    public void setSubmitResults(String msg) {
        showToast("支付成功");
        startActivity(HomePaySuccessActivity.class);
        finish();
    }

    @Override
    public void setPresenter(HomeOrderContract.Presenter presenter) {

    }
}
